First, let’s check if “RCy3”, “igraph”, “RColorBrewer”, “ggraph”, “bio3d” packages are installed. And then, load the packages.
library(RCy3)
library(igraph)
library(RColorBrewer)
library(ggraph)
You can download Cytoscape here.
Launch Cytoscape a new window and import data to Cytoscape using the following:
File > Import > Network from File… and choose data/galFiltered.sif
File > Import > Table from File… and choose data/galExpData.csv
Now let’s set the visual attributes of the nodes (labels and colors) in our network according to the expression data we have just imported. To do this, open the Style panel.
select COMMON for Column under Label
select gal80Rexp for Column under Fill Color
select Continuous Mapping for Column under Fill Color
select gal80Rsig for Column under Shape
5.1 select Continuous Mapping for Column under Shape, and double-click Current Mapping, which is blank right now. This will pop-up a new window.
5.2 click the Add button, and double-click on the left node icon, which is a circle right now. Choose the Rectangle shape and click the Apply button
5.3 click on the black triangle and move the slider to the left, move it to the lower value of 0.05, our threshold for significance
Zoom into this portion of the network and find the three dark red (i.e. highly induced) nodes. Notice that these nodes are in the same region of the graph. Also, there are two nodes that interact with all three red nodes: GAL4 (YPL248C) and GAL11 (YOL051W).
Let’s select these two nodes and their immediate neighbors.
click on GAL4 (YPL248C)
extend the selection by holding down the shift key and clicking on GAL11 (YOL051W)
select their neighbors by pressing Cmd-6 on a Mac (“Select > Nodes > First Neighbors of Selected Nodes > Undirected”)
create a new network by selecting “File > New Network > Selected nodes, all edges”
Our data show precisely this:
Both nodes (GAL4 and GAL11) show fairly small changes in expression, and neither change is statistically significant: they are rendered as light-colored circles.
These slight changes in expression suggest that the critical change affecting the red nodes (GAL1, GAL7 and GAL10) might be somewhere else in the network, and not due to either GAL4 or GAL11.
Note that our network shows that GAL4 interacts with GAL80 (YML051W), which shows a significant level of repression: it is depicted as a blue rectangle.
Note that while GAL80 shows evidence of significant repression, most nodes interacting with GAL4 show significant levels of induction: they are rendered as red rectangles.
GAL11 is a general transcription co-factor with many interactions
To save the graph for reading into other software such as R, use “File > Export > Network to File…”.
Let’s check if we can talk to cytoscape. (Remember to open Cytoscape application now.)
cytoscapePing()
## [1] "You are connected to Cytoscape!"
We can test things further by making a small network and sending it to Cytoscape.
g = makeSimpleIgraph()
createNetworkFromIgraph(g, "myGraph")
## Loading data...
## Applying default style...
## Applying preferred layout...
## networkSUID
## 38624
We can simply plot the graph
plot(g)
Or We can include this Cytoscape rendered network image in our report.
fig <- exportImage(filename="data/demo", type="png", height=350)
## Warning: This file already exists. A Cytoscape popup
## will be generated to confirm overwrite.
knitr::include_graphics("data/demo.png")
Cytoscape provides a number of canned visual styles.
getVisualStyleNames()
## [1] "Marquee" "default black" "Curved"
## [4] "Ripple" "Solid" "Nested Network Style"
## [7] "Sample1" "Sample2" "Big Labels"
## [10] "Minimal" "Sample3" "Gradient1"
## [13] "BioPAX_SIF" "BioPAX" "Directed"
## [16] "Universe" "default" "size_rank"
setVisualStyle("Marquee")
## message
## "Visual Style applied."
We can again include this Cytoscape rendered network image in our report.
fig <- exportImage(filename="data/demo_marquee", type="png", height=350)
## Warning: This file already exists. A Cytoscape popup
## will be generated to confirm overwrite.
knitr::include_graphics("data/demo_marquee.png")
We will read in a species co-occurrence matrix (data/virus_prok_cor_abundant.tsv) that was calculated using Spearman Rank coefficient. (see reference Lima-Mendez et al. (2015) for details)
prok_vir_cor <- read.delim("data/virus_prok_cor_abundant.tsv", stringsAsFactors = FALSE)
rmarkdown::paged_table(prok_vir_cor)
Here we will use the igraph package to convert the co-occurrence dataframe into a network that we can send to Cytoscape.
g <- graph.data.frame(prok_vir_cor, directed = FALSE)
plot(g)
To make the plot looks better, let’s turn off text labels.
plot(g, vertex.label=NA)
Let’s also make the vertex much smaller.
plot(g, vertex.size=3, vertex.label=NA)
Also, let’s use the ggplot extension package for networks called ggraph.
ggraph(g, layout = 'auto') +
geom_edge_link(alpha = 0.25) +
geom_node_point(color="steelblue") +
theme_graph()
## Using `nicely` as default layout
Send this network to Cytoscape.
createNetworkFromIgraph(g,"myIgraph")
## Loading data...
## Applying default style...
## Applying preferred layout...
## networkSUID
## 38652
Community structure detection algorithms try to find dense subgraphs within larger network graphs (i.e. clusters of well connected nodes that are densely connected themselves but sparsely connected to other nodes outside the cluster).
cb = cluster_edge_betweenness(g)
## Warning in cluster_edge_betweenness(g): At community.c:460 :Membership
## vector will be selected based on the lowest modularity score.
## Warning in cluster_edge_betweenness(g): At community.c:467 :Modularity
## calculation with weighted edge betweenness community detection might not
## make sense -- modularity treats edge weights as similarities while edge
## betwenness treats them as distances
plot(cb, y=g, vertex.label=NA, vertex.size=3)
The degree of a node or vertex is its most basic structural property, the number of its adjacent edges. Here we calculate and plot the node degree distribution.
d <- degree(g)
hist(d, breaks=30, col="lightblue", main ="Node Degree Distribution")
plot( degree_distribution(g), type="h" )
Centrality gives an estimation on how important a node or edge is for the connectivity (or the information flow) of a network. It is a particularly useful parameter in signaling networks and it is often used when trying to find drug targets for example.
pr <- page_rank(g)
rmarkdown::paged_table(as.data.frame(pr$vector))
Lets plot our network with nodes size scaled via this page rank centrality scores.
bac_id_affi <- read.delim("data/prok_tax_from_silva.tsv", stringsAsFactors = FALSE)
rmarkdown::paged_table(bac_id_affi)